//index.js
//获取应用实例
const app = getApp()
var util = require("../../../../utils/util.js")
Page({
  data: {
    xianzhi:true,
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    sheet: 0,
    dateil: '对于白血病，根据其不同的时期，治愈的概率也是不一样的，化疗的治愈率大体为40% 左右，白血病是一类造血白细胞',
    voiceList:[
      {
        poster:"https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/doctorDetail/voice.png?sign=913e72f8319b2ac8de6dc1cec669c976&t=1580888655",
        title:"婴幼儿如何预防流感？",
        doctor:"李伟",
        doctorImg:"",
        time:"2020-2-5",
        src:"http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46"
      },
      {
        poster: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/doctorDetail/voice.png?sign=913e72f8319b2ac8de6dc1cec669c976&t=1580888655",
        title: "婴幼儿如何预防流感？",
        doctor: "李伟",
        doctorImg: "",
        time: "2020-2-5",
        src: "http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46"
      },  
    ],
    article:[
      {
        title: "婴幼儿如何预防流感？",
        doctor: "李伟",
        doctorImg: "",
        time: "2020-2-5",
      },
      {
        title: "婴幼儿如何预防流感？",
        doctor: "李伟",
        doctorImg: "",
        time: "2020-2-5",
      },
      {
        title: "婴幼儿如何预防流感？",
        doctor: "李伟",
        doctorImg: "",
        time: "2020-2-5",
      },
    ]
  },

  // 显示更多信息
  morebtns(){
    this.setData({ xianzhi:false})
  },
  // 打开地图
  openoaction(){
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        wx.openLocation({
          latitude,
          longitude,
          scale: 18
        })
      }
    })
  },
  //打电话
  tellsbtn(){
    wx.makePhoneCall({
      phoneNumber: '852852852',
    })
  },
  // 选项卡
  tabdian: function(e) {
    var that = this
    let index = e.currentTarget.dataset.index;
    var uid = that.data.uid
    app.util.request({
      'url': 'entry/wxapp/specialty.lmhj',
      data: {
        uid: uid,
        h_leixing: index
      },
      'cachetime': '30',
      success: function(res) {
        console.log(res)
        that.setData({
          lmlist: res.data,
          sheet: index
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  docinfo(e) {
    var that = this
    var zid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid=' + zid,
    })
  },
  vocieBtn:function(e){
    console.log(e)
    // var item = e.currentTarget.dataset.item
    var lmlist = this.data.lmlist
    console.log(lmlist)
    console.log(app)
    var index = e.currentTarget.dataset.index;
    app.globalData.playIndex= index
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/deveVoice/deveVoice?index=' + index + '&list=' + JSON.stringify(lmlist)
    })
  },
  // 视频按钮
  videoBtn:function(e){
    console.log(e)
    var item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/deveVideo/deveVideo?item='+JSON.stringify(item),
    })
  },
  // 跳转文章详情
  articleBtn:function(e){
    console.log(e)
    var item= e.currentTarget.dataset.item
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/deveArticle/deveArticle?item=' + JSON.stringify(item),
    })
  },
  onLoad: function(options) {
    var uid = options.uid
    var hid = options.hid
    var color = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: color,
    })
    let dateil = this.data.dateil.slice(0, 40) + '...'
    this.setData({
      dateil: dateil,
      uid: uid,
      hid: hid,
      color: color
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  onReady(e) {
    var that = this
    var h_leixing = 0
    that.gethospital_info()
    that.gethospitalmenu()
    that.gethospitaldoctor()
    that.getvide(h_leixing)
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  gethospital_info() {
    var that = this
    var hid = that.data.hid
    app.util.request({
      'url': 'entry/wxapp/specialty.index',
      data: {
        hid: hid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          info: res.data
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  //应用
  gethospitalmenu() {
    var that = this
    var uid = that.data.uid
    app.util.request({
      'url': 'entry/wxapp/specialty.menu',
      data: {
        uid: uid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          server: res.data
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  //专家列表
  gethospitaldoctor() {
    var that = this
    var uid = that.data.uid
    app.util.request({
      'url': 'entry/wxapp/specialty.doctor',
      data: {
        uid: uid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          doctor: res.data
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  getvide(h_leixing) {
    var that = this
    var uid = that.data.uid
    app.util.request({
      'url': 'entry/wxapp/specialty.lmhj',
      data: {
        uid: uid,
        h_leixing: h_leixing
      },
      success: function(res) {
        console.log(res)
        that.setData({
          lmlist: res.data
        })
        // var lmlist = that.data.lmlist
        // for (var i = 0; i < lmlist.length;i++){
        //   var time = (new Date(lmlist[i].sfbtime)).getTime()
        //   console.log(time)
        //   // console.log((new Date(lmlist[i].sfbtime)).getTime())
        //   // var oldTime = (new Date(time)).getTime()
        // }
      },
      fail: function(err) {
        console.log(err)
      },
    })
  }
})